package com.liuweiheng.cloudpayment8004.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

public class SpringUtil implements BeanFactoryPostProcessor {

    private static ConfigurableBeanFactory beanFactory;

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        SpringUtil.beanFactory = configurableListableBeanFactory;
    }


    /**
     * 获取Bean对象
     * @param clz 类对象
     * @param <T> 对象类型
     * @return 对象实例
     */
    public static <T> T getBean(Class<T> clz) {
        return beanFactory.getBean(clz);
    }


}
